package com.wsc.wisdomchina.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.wsc.wisdomchina.R;
import com.wsc.wisdomchina.Tools.Tools;
import com.wsc.wisdomchina.javaBean.wisdomParty.PartyLineTestBean;

import java.util.Date;
import java.util.List;

/**
 * Created by lhg on 2017/9/27.
 */
public class PartyLineTestAdapter extends BaseAdapter {
    private Context mContext;
    private List<PartyLineTestBean> lineTestBeanList;

    public PartyLineTestAdapter(Context mContext, List<PartyLineTestBean> lineTestBeanList) {
        this.mContext = mContext;
        this.lineTestBeanList = lineTestBeanList;
    }

    @Override
    public int getCount() {
        return lineTestBeanList == null ? 0 : lineTestBeanList.size();
    }

    @Override
    public PartyLineTestBean getItem(int position) {
        return lineTestBeanList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        View view = convertView;
        if (view == null) {
            view = LayoutInflater.from(mContext).inflate(R.layout.item_party_line_list, null);
            holder = new ViewHolder(view);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }

        String time = Tools.formatDateTimeyyyyMMDD(new Date(lineTestBeanList.get(position).getCreateTime()), "yyyy.MM.dd");
        holder.item_line_name.setText(lineTestBeanList.get(position).getCheckName());
        holder.item_line_time.setText(time);
        if (!(1 == lineTestBeanList.get(position).getIsOnline())) {
            holder.item_line_go.setVisibility(View.VISIBLE);
            holder.item_line_ove.setVisibility(View.GONE);
        } else {
            holder.item_line_go.setVisibility(View.GONE);
            holder.item_line_ove.setVisibility(View.VISIBLE);
        }
        return view;
    }


    public class ViewHolder {
        private TextView item_line_name;//考试名字
        private TextView item_line_time;//时间
        private TextView item_line_go;//去考试
        private TextView item_line_ove;//已经答题

        public ViewHolder(View view) {
            item_line_name = (TextView) view.findViewById(R.id.line_test_name);
            item_line_time = (TextView) view.findViewById(R.id.line_test_time);
            item_line_go = (TextView) view.findViewById(R.id.line_test_go);
            item_line_ove = (TextView) view.findViewById(R.id.line_test_over);
        }
    }
}
